<?php
namespace Home\Controller;
use Think\Controller;

class IndexController extends CommonController {
    public function index(){
        $this->assign('categories',$this->categories);
        $articles = M("Article")->order("time desc")->limit(3)->select();
        //p($articles);die;
        $this->assign('articles',$articles);
        $this->display();
    }

    public function lst(){
        $id = I("get.id");
        $Category = M("Category");
        $Article = M("Article");
        $category = $Category->where("id='$id'")->find();
        $category['child'] = $Category->where("parent_id='$id'")->select();
        foreach ($category['child'] as $k=>&$v){
            $v['articles'] = $Article->where("category_id=$v[id]")->select();
        }
        //children($category);
        //($category);die;
        $this->assign("category",$category);
        $this->display();
}

    public function category(){
        $id = I("get.id");
        $this->display();
    }

    public function show(){
        $id = I("get.id");
        $article = M("Article")->where("id='$id'")->find();
        $this->assign('article',$article);
        //p($article);
        //json_encode($article);
        $this->display();
    }
}